<template>
	<u-popup :show.sync="showPopup" :round="10" mode="bottom" @close="close">
		<view class="popup_content">
			<view class="top_box">
				<view class="btn">
					供应商
				</view>
				<view class="ipt_box">
					<u-icon name="search" color="#c0c0c0" size="28"></u-icon>
					<input @input="searchSupplier()" v-model="pageInfo.supplier_name" placeholder="关键字查找供应商"
						type="text" />
				</view>
				<view @click="close()" class="text_box">
					关闭
				</view>
			</view>
			<!-- 仓库列表 -->
			<view class="stashList_box">
				<view class="stashItem_box" v-for="(item,index) in supplierList" :key="item.id">
					<view class="left">
						<u-icon name="home-fill" color="#1296db" size="40"></u-icon>
						<text>{{item.supplier_name}}</text>
					</view>
					<view @click="selectStash(item)" class="right">
						选择
					</view>
				</view>
			</view>
		</view>
	</u-popup>
</template>
<script>
	import {
		getWareHouseListApi
	} from '@/api/my.js'
	import {
		getsupplierListApi
	} from '@/api/categoryManage.js'
	export default {
		data() {
			return {
				supplierList: [],
				pageInfo: {
					supplier_name: "", //供应商名字
				},
				timer: ''
			}
		},
		props: {
			showPopup: {
				type: Boolean,
				default: false
			}
		},
		mounted() {
			this.getsupplierList()
		},
		methods: {

			close() {
				this.$emit('update:showPopup', false)
				this.pageInfo = {
					supplier_name: "", //供应商名字
				}
				this.getsupplierList()
			},
			//获取供应商
			async getsupplierList(pageInfo) {
				const {
					data: {
						data: {
							list
						}
					}
				} = await getsupplierListApi(pageInfo)
				this.supplierList = list
			},
			//选择供应商
			selectStash(item) {
				this.$parent.formData.supplier_id = item.id
				this.$parent.supplier_name = item.supplier_name
				this.close()
			},
			//搜索仓库
			searchSupplier() {
				clearTimeout(this.timer)
				this.timer = setTimeout(() => {
					this.getsupplierList(this.pageInfo)
				}, 500)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.popup_content {
		// height: 80vh;

		.top_box {
			display: flex;
			justify-content: space-between;
			font-size: 26rpx;
			padding: 20rpx;

			.btn {
				width: 120rpx;
				height: 70rpx;
				font-weight: 700;
				color: #000;
				text-align: center;
				line-height: 70rpx;


			}

			.ipt_box {
				display: flex;
				align-items: center;
				width: 480rpx;
				height: 70rpx;
				padding: 0 20rpx;
				background-color: #f2f2f2;
				border-radius: 35rpx;
				box-sizing: border-box;

				input {
					margin-left: 20rpx;
				}
			}

			.text_box {
				color: #60aeff;
				line-height: 70rpx;
			}
		}

		.stashList_box {
			height: 1000rpx;
			overflow: auto;
		}

		.stashItem_box {
			border-bottom: 1px solid #f2f2f2;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;

			.left {
				display: flex;
				align-items: center;
				font-weight: 700;

				text {
					margin-left: 20rpx;
				}
			}

			.right {
				width: 180rpx;
				height: 60rpx;
				background-color: #39cccc;
				color: #fff;
				text-align: center;
				line-height: 60rpx;
				border-radius: 35rpx;
			}
		}
	}
</style>